package plugin.eos.awake.flutter.awake1.network;

import android.app.Activity;
import android.content.Context;

import java.lang.ref.WeakReference;

/**
 * <pre>
 *     author: Blankj
 *     blog  : http://blankj.com
 *     time  : 16/12/08
 *     desc  : Utils初始化相关
 * </pre>
 */
public class ContextUtils {

    private static Context application;
    private static WeakReference<Activity> mNowContext;

    private ContextUtils() {
        throw new UnsupportedOperationException("u can't instantiate me...");
    }

    /**
     * 初始化工具类
     *
     * @param context 上下文
     */
    public static void init(Context context) {
        ContextUtils.application = context.getApplicationContext();
    }

    /**
     * 获取ApplicationContext
     *
     * @return ApplicationContext
     */
    public static Context getApplication() {
        if (application != null) return application;
        throw new NullPointerException("u should init first");
    }

    static Activity getmNowContext() {
        return mNowContext != null ? mNowContext.get():null;
    }

    public static void setmNowContext(Activity mNowContext) {
        ContextUtils.mNowContext = new WeakReference<>(mNowContext);
    }
}